<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-02-07 08:50:24
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-07-03 17:04:29
 * @Description: 
 * 
-->
<template>
	<el-card shadow="never" header="个人信息">
		<el-form ref="form" :model="form" label-width="120px" style="margin-top:20px;">
			<el-form-item label="头像">
				<sk-upload v-model="form.attachments" :limit="1" :showbutton="false">
				</sk-upload>
			</el-form-item>
			<el-form-item label="账号">
				<el-input v-model="form.username" disabled></el-input>
				<div class="el-form-item-msg">账号信息用于登录，系统不允许修改</div>
			</el-form-item>
			<el-form-item label="邮箱">
				<el-input v-model="form.email"></el-input>
			</el-form-item>
			<el-form-item label="姓名">
				<el-input v-model="form.name"></el-input>
			</el-form-item>
			<el-form-item label="性别">
				<el-select v-model="form.sex_id" placeholder="请选择">
					<el-option label="保密" value="0"></el-option>
					<el-option label="男" value="1"></el-option>
					<el-option label="女" value="2"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="个性签名">
				<el-input v-model="form.about" type="textarea"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
export default {
	props: {
		modelValue: { type: Boolean, default: false },
		item: { type: Object, default: () => { } }
	},
	data() {
		let userinfo = this.$TOOL.data.get("USER_INFO");
		return {

			form: userinfo,
			showloading: this.modelValue,
		}
	},
	watch: {
		showloading(val) {
			this.$emit("update:modelValue", val)
		}
	},
	methods: {
		async save() {
			this.showloading = true;
			setTimeout(() => {
				this.showloading = false;
			}, 3000);
			var res = await this.$API.system.user.save.post({
				id: this.form.id,
				sex_id: this.form.sex_id,
				email: this.form.email,
				name: this.form.name,
				about: this.form.about,
				attachments: this.form.attachments
			});
			this.showloading = false;
			if (res.code == 200) {
				this.$message.success("操作成功");
				this.$TOOL.data.set("USER_INFO", res.data);
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
		}
	}

}
</script>

<style></style>
